package org.rooster.chromosomeevaluator.rules;

import org.jgap.IChromosome;
import org.rooster.chromosomeevaluator.common.ScheduleMetrix;
import org.rooster.genetic.GenericRule;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 6/5/12
 * Time: 9:10 PM
 * To change this template use File | Settings | File Templates.
 */
public class SameEmployeeForTwoSectionsAtSameTimeSlotPenaltyRule implements GenericRule{

    private int weight = 1;

    public SameEmployeeForTwoSectionsAtSameTimeSlotPenaltyRule() {
    }

    public SameEmployeeForTwoSectionsAtSameTimeSlotPenaltyRule(int weight) {
        this.weight = weight;
    }

    /**
     * If the same employee is assigned to two sections in the same time slot
     * this method adds a penalty value for it
     * @param chromosome
     * @return  the total penalty value
     */

    @Override
    public double fitnessValueForRule(IChromosome chromosome) {
        int penalty = 1;
//        int thisSection = 0;
//        int otherSection = 0;
//        int thisSectionSlotStart = 0;
//        int otherSectionSlotStart = 0;
//        int thisSectionSlotEnd = 0;
//        int otherSectionSlotEnd = 0;
//        Gene[] genes = chromosome.getGenes();
//        for (int i = 0; i< TaskManager.NO_OF_TIME_SLOTS; i++) {
//            for(int j=0; j< TaskManager.NO_OF_SECTIONS; j++) {
//                for(int k=j+1; k< TaskManager.NO_OF_SECTIONS; k++) {
//                    thisSection = j;
//                    otherSection = k;
//                    thisSectionSlotStart = GeneIndex.getTimeSlotStart(j, i);
//                    otherSectionSlotStart = GeneIndex.getTimeSlotStart(k, i);
//                    thisSectionSlotEnd = GeneIndex.getTimeSlotEnd(j, i);
//                    otherSectionSlotEnd = GeneIndex.getTimeSlotEnd(k, i);
//
//                    for(int l=thisSectionSlotStart; l<=thisSectionSlotEnd; l++) {
//                        for (int m=otherSectionSlotStart; m<=otherSectionSlotEnd; m++) {
//                            if(genes[l].getAllele().equals(genes[m].getAllele())) {
//                                penalty++;
////                                System.out.print("| emp id:"+ genes[l].getAllele()+" ts:"+ i +" secs:" +j+","+k+"");
//                            }
//                        }
//                    }
//
//                }
//
//            }
//        }
//        System.out.println("");
        penalty = ScheduleMetrix.getScheduleMetrixInstance().getNumberOfDuplicayionsInTwoSection() + 1;
        return 1.0/(penalty * weight);
    }

    @Override
    public int getWeight() {
        return weight;
    }

    @Override
    public void setWeight(int value) {
        this.weight = value;
    }
}
